/*=======================================*/
/*	登陆功能的js                           */
/*	@author Wendel                       */
/*=======================================*/

$(document).ready(function(){
	$("#userName").focus(function (){
		$("#userName").val("");
		$("#userName").css({fontSize:"12px",color:"#000"});
	});
	$("#passWord").focus(function (){
		$("#passWord").attr("type","password");
		$("#passWord").val("");
		$("#passWord").css({fontSize:"12px",color:"#000"});
	});
	$("#customLoginBtn").on('click',function(){
		//alert($("#userName").val());
		if($("#userName").val() == "" || $("#userName").val == null || $("#userName").val == "用户名不能为空!"){
			$("#userName").val("用户名不能为空!");
			$("#userName").css({fontSize:"12px",color:"red"});
		}
		else if($("#passWord").val() == "" || $("#passWord").val == null || $("#passWord").val() == "密码不能为空!"){
			$("#passWord").attr("type","text");
			$("#passWord").val("密码不能为空!");
			$("#passWord").css({fontSize:"12px",color:"red"});
		}
		else{
			login();
		}
    });
	// 按回车执行查询
	$("#userName").on("keypress", function(){
		var event = arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异 
		if (event.keyCode == 13) {
//			$("#loginForm").submit();
			login();
		} // 回车键的键值为13
	}); 
	$("#passWord").on("keypress", function(){
		var event = arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异 
		if (event.keyCode == 13) {
			login();
		} // 回车键的键值为13
	}); 
});

function login(){
	var datasent = $("#customLoginForm").serializeObject();
	params = JSON.stringify(datasent); 
	$.ajax({
		type : "POST",
		url : "/customjsp/login/loginCheck",
		dataType : "json",
		contentType : "application/json;charset=utf-8",
		data : params,
		async : false,  //同步或异步
		success : function(data) {
			if(data.resultCode == 0){   //登录成功
				window.location.href="/customjsp/index";
			}else{
				alert(data.resultMessage);
			}
			//btn.button('reset');
		}
	});
}

